package cn.com.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.Lifecycle;
import org.springframework.stereotype.Component;

@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor, Lifecycle {

	private boolean isRunning = false;

	public MyBeanFactoryPostProcessor() {
		super();
		System.out.println("这是BeanFactoryPostProcessor实现类构造器！！");
	}

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory arg0)
			throws BeansException {
		System.out
				.println("BeanFactoryPostProcessor调用postProcessBeanFactory方法");
		BeanDefinition bd = arg0.getBeanDefinition("person");
		bd.getPropertyValues().addPropertyValue("phone", "110");
	}

	@Override
	public void start() {
		System.out.println("【MyBeanFactoryPostProcessor】调用<bean>的start属性指定的初始化方法");
		isRunning = true;
	}

	@Override
	public void stop() {
		System.out.println("【MyBeanFactoryPostProcessor】调用<bean>的stop属性指定的初始化方法");
	}

	@Override
	public boolean isRunning() {
		return isRunning;
	}
}
